package com.hqd.test.xml;

import com.hqd.ch03.v1.SpringImitationV1;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;

public class DomParse {
    public static Document parse(org.w3c.dom.Document doc) throws Exception {
        org.dom4j.io.DOMReader xmlReader = new org.dom4j.io.DOMReader();
        return xmlReader.read(doc);
    }


    public static org.w3c.dom.Document parse(Document doc) throws Exception {
        java.io.StringReader reader = new java.io.StringReader(doc.asXML());
        org.xml.sax.InputSource source = new org.xml.sax.InputSource(reader);
        javax.xml.parsers.DocumentBuilderFactory factory =
                javax.xml.parsers.DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        javax.xml.parsers.DocumentBuilder documentBuilder = factory.
                newDocumentBuilder();
        return documentBuilder.parse(source);
    }

    public static void main(String[] args) {
        SAXReader reader = new SAXReader();
        try {
            Document document = reader.read(SpringImitationV1.class.getClassLoader().getResource("v7/bean.xml"));
            org.w3c.dom.Document parse = parse(document);
            System.out.println(parse.getDocumentElement().getNamespaceURI());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
